package edu.friday_2025_04_27.service.impl;
import edu.friday_2025_04_27.common.result.TableDataInfo;
import edu.friday_2025_04_27.model.SysUser;
import edu.friday_2025_04_27.model.vo.SysUserVO;
import edu.friday_2025_04_27.repository.SysUserRepository;
import edu.friday_2025_04_27.service.SysUserService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class SysUserServiceImpl implements SysUserService {
    @Autowired
    SysUserRepository sysUserRepository;
    @Override
    public List<SysUser> selectUserList() {
        return sysUserRepository.findAll();
    }

    @Override
    public TableDataInfo selectUserList(SysUserVO userVO, Pageable pageable){
        SysUser sysUser = new SysUser();
        BeanUtils.copyProperties(userVO,sysUser);
        sysUser.setDelFlag('0');

        ExampleMatcher matcher = ExampleMatcher.matching()
                .withMatcher("username", ExampleMatcher.GenericPropertyMatchers.exact())
                .withMatcher("phonenumber", ExampleMatcher.GenericPropertyMatchers.exact());

        Example<SysUser> example = Example.of(sysUser, matcher);
        Page<SysUser> page = sysUserRepository.findAll(example,pageable);
        return TableDataInfo.success(page.toList(),page.getTotalElements());
    }
}
